﻿package net.jmp0.toast.entities.obstacles 
{
	import net.jmp0.toast.entities.bases.GameElement;
	import net.jmp0.toast.entities.effects.GoalShining;
	import net.jmp0.toast.entities.obstacles.Obstacle;
	import net.jmp0.toast.levels.GameLevel;
	import net.jmp0.toast.levels.LevelTracker;
	import punk.Actor;
	
	/**
	 * ...
	 * @author Thodd
	 */
	public class Goal extends Obstacle
	{
		[Embed(source = '../../res/goal.png')] private var imgSprite:Class;

		//just the little green shining effect around the goal
		private var shine:Actor;
		
		//The message that is shown after clearing the level
		//this String will be passed on to a "betweenscreen" which is shown between 2 levels
		private var message:String = "Congratulations!";
	
		/**
		 * Contructur for Goal objects
		 * @param	x The x coordinate
		 * @param	y The y coordinate
		 * @param	message The message which is shown after clearing the level
		 */
		public function Goal(x:int, y:int, message:String) 
		{
			super(x, y);
			this.message = message;
			
			this.shine = new GoalShining(x-20, y-20);
			
			//Standard setup stuff
			this.sprite = FP.getSprite(imgSprite, 20, 20, false, false, 0, 0, true);
			this.randomizeAnimation();
		}

		
		/**
		 * Implementation of the level changing after touching the goal
		 * @param	colPartner this method doesn't care for the colPartner
		 */
		override public function performCollision(colPartner:GameElement):void {
			trace("collision with goal" + this.getID());
			//check if there are still some levels left to play
			if (LevelTracker.getInstance().hasNext()) {
				LevelTracker.getInstance().switchToLevelWithMessage(LevelTracker.getInstance().next(), message);
			}
		}
		
		
		override public function destroy():void {
			//first removing the shine and then destroying itself
			FP.world.remove(shine);
			super.destroy();
		}
	}

}